#! /usr/bin/python3
# _*_ coding:UTF-8 _*_
"""
    获取对象信息
"""


class Animal(object):

    def __init__(self):
        self.x = None

    def run(self):
        print('animal is running>>>>')


class Dog(Animal):

    def run(self):
        print('Dog is running>>>>>>')


class Husky(Dog):

    def run(self):
        print('Husky is running>>>>>>>>>>>>')


class Cat(Animal):

    def run(self):
        print('Cat is running>>>>>>>')


class People(object):

    def run(self):
        print('People is running>>>>>>>')


def main():
    # 判断对象类型 type isinstance
    print(type(123))    # <class 'int'>
    print(type('123'))   # <class 'str'>
    print(type(False))    # <class 'bool'>
    print(type(None))    # <class 'NoneType'>
    print(type(int))    # <class 'type'>
    print(type(abs))     # <class 'builtin_function_or_method'>
    # 用于if语句中：
    # print(type(123) == type(456))    # True 没问题 但最好不用
    print(type(123) == int)    # True 没问题 但最好不用
    # print(type('abc') == type('123'))
    print(type('abc') == str)
    # 使用isinstance 对于了类 以及继承关系
    a = Animal()
    d = Dog()
    h = Husky()
    print('a 是 Animal类：', isinstance(a, Animal))
    print('d 是 Animal类：', isinstance(d, Animal))
    print('h 是 Animal类：', isinstance(h, Animal))
    print('a 是 Dog类：', isinstance(a, Dog))
    print('d 是 Dog类：', isinstance(d, Dog))
    print('h 是 Dog类：', isinstance(h, Dog))
    print('a 是 Husky类：', isinstance(a, Husky))
    print('d 是 Husky类：', isinstance(d, Husky))
    print('h 是 Husky类：', isinstance(h, Husky))
    # 判断基本类型
    print(isinstance(123, int))
    print(isinstance('123', str))
    # 判断是类型中的之一  总是优先使用isinstance()判断类型，可以将指定类型及其子类“一网打尽”。
    print(isinstance([1, 2, 3], (list, tuple)))
    # dir() 获得一个对象的所有属性和方法
    print(dir('123'))


if __name__ == '__main__':
    main()
